package org.luxor.commons.storage.client.fastdfs;

import com.luhuiguo.fastdfs.conn.FdfsConnectionPool;
import org.luxor.commons.storage.client.AbstractStorageProperties;
import org.luxor.commons.storage.config.HttpConfig;
import org.luxor.commons.storage.config.ThumbImageConfig;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

import java.util.List;

/**
 * FastDFS-Client 配置
 *
 * @author Mr.Yan  @date 2019/12/12
 */
@ConfigurationProperties(prefix = FastDfsProperties.PREFIX)
public class FastDfsProperties extends AbstractStorageProperties {

    public static final String PREFIX = "spring.storage.fast-dfs";

    final Boolean DEFAULT_ENABLED = Boolean.FALSE;
    final Integer DEFAULT_CHUNK_SIZE = 5;
    final Integer DEFAULT_DOWNLOAD_CHUNK_SIZE = 100;
    final HttpConfig DEFAULT_HTTP = new HttpConfig();
    final ThumbImageConfig DEFAULT_THUMB_IMAGE = new ThumbImageConfig();

    final String DEFAULT_GROUP_NAME = "group1";
    final Integer DEFAULT_SOTIMEOUT = 1500;
    final Integer DEFAULT_CONNECT_TIMEOUT = 600;
    final FdfsConnectionPool DEFAULT_POOL = new FdfsConnectionPool();

    /**
     * 是否启用
     */
    private boolean enabled;

    /**
     * 分块大小
     */
    private Integer chunkSize;
    private Integer downloadChunkSize;

    /**
     * 缩略图配置
     */
    @NestedConfigurationProperty
    private ThumbImageConfig thumbImage;

    /**
     * 防盗链配置
     */
    @NestedConfigurationProperty
    private HttpConfig http;

    /**
     * 请求超时时间
     */
    private Integer soTimeout;
    /**
     * 连接超时时间
     */
    private Integer connectTimeout;

    /**
     * 分组名
     */
    private String groupName;
    /**
     * 跟踪节点
     */
    private List<String> trackerList;

    /**
     * 连接池配置
     */
    @NestedConfigurationProperty
    private FdfsConnectionPool pool;


    public FastDfsProperties() {
        super();
        this.enabled = DEFAULT_ENABLED.booleanValue();
        this.chunkSize = DEFAULT_CHUNK_SIZE;
        this.downloadChunkSize = DEFAULT_DOWNLOAD_CHUNK_SIZE;
        this.thumbImage = DEFAULT_THUMB_IMAGE;
        this.http = DEFAULT_HTTP;

        this.soTimeout = DEFAULT_SOTIMEOUT;
        this.connectTimeout = DEFAULT_CONNECT_TIMEOUT;
        this.groupName = DEFAULT_GROUP_NAME;
        this.pool = DEFAULT_POOL;
    }

    @Override
    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public Integer getChunkSize() {
        return chunkSize;
    }

    public void setChunkSize(Integer chunkSize) {
        this.chunkSize = chunkSize;
    }

    public Integer getDownloadChunkSize() {
        return downloadChunkSize;
    }

    public void setDownloadChunkSize(Integer downloadChunkSize) {
        this.downloadChunkSize = downloadChunkSize;
    }

    @Override
    public ThumbImageConfig getThumbImage() {
        return thumbImage;
    }

    public void setThumbImage(ThumbImageConfig thumbImage) {
        this.thumbImage = thumbImage;
    }

    @Override
    public HttpConfig getHttp() {
        return http;
    }

    public void setHttp(HttpConfig http) {
        this.http = http;
    }

    public Integer getSoTimeout() {
        return soTimeout;
    }

    public void setSoTimeout(Integer soTimeout) {
        this.soTimeout = soTimeout;
    }

    public Integer getConnectTimeout() {
        return connectTimeout;
    }

    public void setConnectTimeout(Integer connectTimeout) {
        this.connectTimeout = connectTimeout;
    }

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public List<String> getTrackerList() {
        return trackerList;
    }

    public void setTrackerList(List<String> trackerList) {
        this.trackerList = trackerList;
    }

    public FdfsConnectionPool getPool() {
        return pool;
    }

    public void setPool(FdfsConnectionPool pool) {
        this.pool = pool;
    }

}
